<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<%@include file="../../common/mastertop.jsp"%>
<p class="page-title">
	<i class="locale-icon"></i> <span>当前位置 : </span> <span
		class="cur-page-title">用户管理</span> <span>· 角色列表</span>
</p>

<form class="form-inline clearfix" id="seachform"
	action="${pageContext.request.contextPath}/set/role/index"
	method="post">

	<div class="filter-warp rect-fff clearfix">
		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">角色编号</span> <input type="text"
				class="form-control form-control-260" name="roleId"
				value="${model.roleId}">
		</div>

		<div class="form-group col-xs-6 col-lg-4">
			<span class="form-label">角色名称</span> <input type="text"
				class="form-control form-control-260" name="roleName"
				value="${model.roleName}">
		</div>

		<div class="col-xs-12  text-center">
			<button type="button" class="btn runmi-primary buttonrole"
				onclick="edit('')" name="btnadd">新&nbsp;增</button>
			<button type="button" class="btn runmi-primary search-btn"
				onclick="seach()">查询</button>
		</div>
	</div>

	<div class="rect-fff table-warp">
		<div class="table-scroll">
			<table>
				<tr>
					<th width="160">操作</th>
					<th>角色编号</th>
					<th>角色名称</th>
					<th>创建人</th>
					<th>创建时间</th>
					<th>修改人</th>
					<th>修改时间</th>
				</tr>
				<c:forEach items="${model.items}" var="item" varStatus="itemStatus">
					<tr id="row_${item.id}">
						<td width="160"><span class="rm-table-btn buttonrole"
											  onclick="edit('${item.id}');" name="btnedit">修改</span> <span
								class="rm-table-btn buttonrole" onclick="configMenu('${item.id}');"
								name="btnrole">权限设置</span> <span class="rm-table-btn buttonrole"
																 onclick="del('${item.id}');" name="btndel">删除</span></td>
						<td>${item.id}</td>
						<td>${item.roleName}</td>
						<td>${item.createUserName}</td>
						<td><fmt:formatDate value="${item.createTime}" type="both"
											pattern="yyyy-MM-dd HH:mm:ss" /></td>
						<td>${item.updateUserName}</td>
						<td><fmt:formatDate value="${item.updateTime}" type="both"
											pattern="yyyy-MM-dd HH:mm:ss" /></td>

					</tr>
				</c:forEach>
			</table>
		</div>
		<vp:pages cpage="${model.cpage}" totalCount="${model.totalCount}"
			pageSize="${model.pageSize}" />

	</div>

</form>
<script type="text/javascript">
	function seach() {
		$("#cpage").val(1);
		oksubmit();
	}
	function oksubmit() {
		$("#btnOk").attr("disabled", "disabled");
		var objform = document.getElementById('seachform');
		objform.submit();
	}
	function del(id) {
		layer.confirm('确认要删除此角色吗', {
			 title :'确认删除',
			btn : [ '确认', '取消' ]
		//按钮
		}, function() {
			sendOpTo(id);
		}, function() {

		});
	}
	function sendOpTo(id) {
		layer.load(1, {
			shade : [ 0.5, '#fff' ]
		});
		var postData = "roleId=" + id;
		$.ajax({
			type : "POST",
			url : "delRole",
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			dataType : 'json',
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				if (resultdata.returnCode == "0000") {
					layer.alert('操作成功', {
						icon : 1
					}, function() {
						layer.closeAll();
						oksubmit();
					});
				} else {
					layer.alert(resultdata.returnMessage);
				}
			}
		});
	}

	function editReturn() {
		layer.closeAll();
		oksubmit();
	}
	function closeAll() {
		layer.closeAll();
	}
	function edit(id) {
		var domainUrl = "edit?roleId=" + id;
		layer.open({
			type : 2,
			title : '角色',
			area : [ '450px', '320px' ],
			content : domainUrl
		//iframe的url
		});
		// $('#wrap').hide();
		// $('#editFrame').attr("src", domainUrl);
		//$('#edit').show(); 
	}
	function configMenu(id) {
		var domainUrl = "config?roleId=" + id;
		location.href=domainUrl;

	}
	function reset(userId) {
		var postData = "userId=" + userId;
		$.ajax({
			type : "POST",
			url : "resetPassword",
			data : postData,
			contentType : "application/x-www-form-urlencoded;charset=UTF-8",
			async : true, // 同步  true 异步。默认是异步
			dataType : 'json',
			error : function(resultdata) {
				layer.closeAll();
			},
			success : function(resultdata) {
				layer.closeAll();
				if (resultdata.returnCode == "0000") {
					layer.alert('操作成功', {
						icon : 1
					}, function() {
						layer.closeAll();
						oksubmit();
					});
				} else {
					layer.alert(resultdata.returnMessage);
				}
			}
		});
	}
</script>
<%@include file="../../common/masterbottom.jsp"%>
